package com.chen.judge;

import com.chen.judge.codesandbox.model.JudgeContext;
import com.chen.judge.codesandbox.model.JudgeResult;
import com.chen.judge.strategy.*;
import com.chen.judge.strategy.StrategyImpl.CPPLanguageJudgeStrategy;
import com.chen.judge.strategy.StrategyImpl.DefaultJudgeStrategy;
import com.chen.judge.strategy.StrategyImpl.JavaLanguageJudgeStrategy;
import com.chen.judge.strategy.StrategyImpl.PythonLanguageJudgeStrategy;
import com.chen.popj.entity.ProblemSubmit;
import org.springframework.stereotype.Service;

/**
 * 判题管理（简化调用）
 */
@Service
public class JudgeManager {

    /**
     * 执行判题
     *
     * @param judgeContext
     * @return
     */
    JudgeResult doJudge(JudgeContext judgeContext) {
        ProblemSubmit problemSubmit = judgeContext.getProblemSubmit();
        String language = problemSubmit.getLanguage();
        new DefaultJudgeStrategy();
        JudgeStrategy judgeStrategy = switch (language.toLowerCase()) {
            case "c", "c++" -> new CPPLanguageJudgeStrategy();
            case "java" -> new JavaLanguageJudgeStrategy();
            case "python" -> new PythonLanguageJudgeStrategy();
            default -> new DefaultJudgeStrategy();
        };
        return judgeStrategy.doJudge(judgeContext);
    }

}
